{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 环境配置"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "pip install vllm \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pip install flash-attn --no-build-isolation \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " ## 单卡 \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "vllm serve Qwen3-8B --dtype auto --port 6006  --max_model_len 8784 --gpu_memory_utilization 0.8\n",
    "\n",
    "\n",
    "Qwen3-8B：模型权重位置 \\\n",
    "dtype：数据类型，一般直接auto就可以了，低版本的显卡可能需要自己设置，如2080要设置为half \\\n",
    "port：端口号 \\\n",
    "limit_mm_per_prompt image=4，默认是1，这样每次请求可以输入多张图片 \\\n",
    "max_model_len：每次全球最大的token长度，爆显存了就改小 \\\n",
    "gpu_memory_utilization：GPU最大利用率，爆显存了就改小，我现在一般设置为0.7-0.8 \\\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 多卡"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "vllm serve Qwen3-8B --dtype half --port 6006 --tensor-parallel-size 2 --pipeline-parallel-size 2 --gpu-memory-utilization 0.7  --max_model_len 8784\n",
    "\n",
    "tensor-parallel-size：模型的权重将被分割成n部分分布在GPU上。\\\n",
    "pipeline-parallel-size：设置流水线并行的大小为k，意味着模型的不同层将被分布到k个GPU上。\\\n",
    "保证n*k=卡的数量，正好等于您拥有的GPU数量。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## open-webui"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pip install open-webui"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "source /etc/network_turbo\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "vllm serve Qwen3-8B --dtype auto --port 5000 --max_model_len 8784 --gpu_memory_utilization 0.8"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "export HF_ENDPOINT=https://hf-mirror.com \\\n",
    "export ENABLE_OLLAMA_API=False \\\n",
    "export OPENAI_API_BASE_URL=http://127.0.0.1:5000/v1 \\\n",
    "export DEFAULT_MODELS=\"Qwen3-8B\" \\\n",
    "open-webui serve --port 6006"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " http://localhost:8000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## openai格式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pip install openai"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "python -m vllm.entrypoints.openai.api_server --served-model-name Qwen3-8B --model /root/autodl-tmp/Qwen/Qwen3-8B --dtype auto --port 6006 --max_model_len 8784 --gpu_memory_utilization 0.8"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
